﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Configuration;

namespace Cosoware.Web.Documents.SqlClient
{
    public class SqlDocumentsRepositoryModule : DocumentsRepositoryModuleBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="SqlDocumentsRepositoryModule"/> class.
        /// </summary>
        public SqlDocumentsRepositoryModule()
        {
        }

        /// <summary>
        /// Gets the repository provider.
        /// </summary>
        /// <returns></returns>
        protected override RepositoryProvider GetRepositoryProvider()
        {
            var provider = new SqlRepositoryProvider();
            LoadConfiguration(provider);
            return provider;
        }

        /// <summary>
        /// Loads the configuration.
        /// </summary>
        /// <param name="provider">The provider.</param>
        private void LoadConfiguration(SqlRepositoryProvider provider)
        {
            var section = (SqlDocumentsRepositoryConfigurationSection) WebConfigurationManager.GetSection("cosowareSqlDocumentsRepository");
            provider.ConnectionString = WebConfigurationManager.ConnectionStrings[section.ConnectionString].ConnectionString;
        }
    }
}
